#include "GameManager.hpp"

namespace mindsweeper {
namespace main {

GameManager::GameManager(GameMain *game_main) :
	gameMain(game_main)
{
	// Initialize the games
	this->maze = new maze::Maze(gameMain);

	// Initialize the current game to the maze game.
	this->changeGame("maze");
}

Game& GameManager::changeGame(std::string new_game) {
	// Make the new game name lowercase.
	boost::algorithm::to_lower(new_game);

	// Set the current game based on the lowercase string
	if (new_game == "maze")
		this->currentGame = maze;
	
	// Run the new game's init function
	this->currentGame->init();
	
	// Return a reference to the current game
	return *this->currentGame;
}

void GameManager::processEvent(sf::Event &event) {
	switch (event.Type) {
		default:
			// Forward the event to the current game.
			this->currentGame->processEvent(event);
			break;
	}
}

void GameManager::render() {
	this->currentGame->render();
}

void GameManager::update() {
	this->currentGame->update();
}

// End namespaces
}
}
